package com.example.adminvue.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.adminvue.domain.BInfo;
import com.example.adminvue.mapper.BInfoMapper;
import com.example.adminvue.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import static com.example.adminvue.utils.SecurityUtils.getLoginUser;

/**
*
*/
@Service
public class BInfoService
{
    @Autowired
    private BInfoMapper bInfoMapper;

    public List<BInfo> selectList(BInfo info) {
        LambdaQueryWrapper<BInfo> wrapper = new LambdaQueryWrapper();
        if(StringUtils.isNotEmpty(info.getInfoTitle())){
            wrapper.like(BInfo::getInfoTitle,info.getInfoTitle());
        }

        List<BInfo> list = bInfoMapper.selectList(wrapper);
        return list;
    }

    public BInfo selectById(Long id) {
        BInfo info = bInfoMapper.selectById(id);
        return info;
    }

    public int insert(BInfo info) {
        info.setCreateBy(getLoginUser().getUsername());
        return bInfoMapper.insert(info);
    }

    public int update(BInfo info) {
        info.setUpdateBy(getLoginUser().getUsername());
        return bInfoMapper.updateById(info);
    }

    public int deleteById(Long id) {
        return bInfoMapper.deleteById(id);
    }
}
